package com.ambulance.project.biz.controller.pad;

import com.ambulance.common.exception.CustomException;
import com.ambulance.common.utils.ResultMapUtil;
import com.ambulance.framework.aspectj.lang.annotation.Log;
import com.ambulance.framework.aspectj.lang.enums.BusinessType;
import com.ambulance.framework.aspectj.lang.enums.OperatorType;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.domain.AjaxResultData;
import com.ambulance.project.biz.entity.*;
import com.ambulance.project.biz.service.*;
import com.ambulance.project.manager.utils.DoctorAndNurseCommonUtil;
import com.ambulance.project.manager.utils.PadUserLoginResult;
import com.ambulance.utils.CommonUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author RXL
 * @Date 2020/4/26 14:29
 * @Version 1.0
 */


@Api(tags = {"随车医生-电子病历相关接口"})
@RequestMapping(value = "/pad/v1/dispatch/case", method = RequestMethod.POST)
@Controller
public class DispatchCaseController {

    @Autowired
    private DispatchCaseService dispatchCaseService;
    @Autowired
    private DispatchService dispatchService;
    @Autowired
    private CaseChangeLogService caseChangeLogService;
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private NurseService nurseService;
    @Autowired
    private PatientService patientService;
    @Autowired
    private DoctorAndNurseCommonUtil doctorAndNurseCommonUtil;
    @Autowired
    private DoctorAndNurseCommonUtil padCommonUtil;
    @Autowired
    private CarService carService;

    @RequestMapping(value = "/add")
    @ResponseBody
    @ApiOperation(value = "添加病历", notes = "选择医院逻辑为:首次默认显示120调度医院,如果需要更改目标医院,只能通过选择下拉医院列表中进行更改", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientName", value = "患者姓名", required = false, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "patientSex", value = "患者性别", required = false, paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "patientAge", value = "患者年龄", required = false, paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "patientMobile", value = "患者联系方式", required = false, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "patientAddress", value = "患者地址", required = false, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "majorCase", value = "主诉情况", required = false, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "baseHelp", value = "初步诊断", required = false, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "treatmentRecord", value = "既往病史", required = false, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "medicineSensitive", value = "过敏史", required = false, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "nhissScore", value = "nhiss评分", required = false, paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "gcsScore", value = "gcs评分", required = false, paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "treatMeasure", value = "抢救措施", required = false, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "medicine", value = "用药情况", required = false, paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "hospitalID", value = "医院编号", required = false, paramType = "form", dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    /**
     * 供调度过程中第一次填写病历
     */
    @Log(title = "添加电子病历", businessType = BusinessType.OTHER, operatorType = OperatorType.MOBILE)
    public Object add(
            @RequestParam(value = "patientName", required = false) String patientName,
            @RequestParam(value = "patientSex", required = false) String sex,
            @RequestParam(value = "patientAge", required = false) String patientAge,
            @RequestParam(value = "patientMobile", required = false) String patientMobile,
            @RequestParam(value = "patientAddress", required = false) String patientAddress,
            @RequestParam(value = "majorCase", required = false) String majorCase,
            @RequestParam(value = "baseHelp", required = false) String baseHelp,
            @RequestParam(value = "treatmentRecord", required = false) String treatmentRecord,
            @RequestParam(value = "medicineSensitive", required = false) String medicineSensitive,
            @RequestParam(value = "nhissScore", required = false) String nhissScore,
            @RequestParam(value = "gcsScore", required = false) String gcsScore,
            @RequestParam(value = "treatMeasure", required = false) String treatMeasure,
            @RequestParam(value = "medicine", required = false) String medicine,
            @RequestParam(value = "hospitalID", required = false) Integer hospitalID
//            @RequestBody DispatchCase dispatchCase
    ) {
        PadUserLoginResult padLoginUser = padCommonUtil.getPadLoginUser();
        Integer uid = padLoginUser.getUid();
        Dispatch dispatchServiceById = doctorAndNurseCommonUtil.getDispatch();

        final DispatchCase dispatchCase = new DispatchCase();
        if (!CommonUtils.checkNull(patientName)) {
            dispatchCase.setPatientName(patientName);
        }
        if (!CommonUtils.checkNull(sex) && !"null".equals(sex)) {
            dispatchCase.setPatientSex(Integer.parseInt(sex));
        }
        if (!CommonUtils.checkNull(patientAge) && !"null".equals(patientAge)) {
            dispatchCase.setPatientAge(Integer.parseInt(patientAge));
        }
        if (!CommonUtils.checkNull(patientMobile)) {
            dispatchCase.setPatientMobile(patientMobile);
        }
        if (!CommonUtils.checkNull(patientAddress)) {
            dispatchCase.setPatientAddress(patientAddress);
        }
        if (!CommonUtils.checkNull(majorCase)) {
            dispatchCase.setMajorCase(majorCase);
        }
        if (!CommonUtils.checkNull(baseHelp)) {
            dispatchCase.setBaseHelp(baseHelp);
        }
        if (!CommonUtils.checkNull(treatmentRecord)) {
            dispatchCase.setTreatmentRecord(treatmentRecord);
        }
        if (!CommonUtils.checkNull(medicineSensitive)) {
            dispatchCase.setMedicineSensitive(medicineSensitive);
        }
        if (!CommonUtils.checkNull(nhissScore) && !"null".equals(nhissScore)) {
            dispatchCase.setNhissScore(Integer.parseInt(nhissScore));
        }
        if (!CommonUtils.checkNull(gcsScore) && !"null".equals(gcsScore)) {
            dispatchCase.setGcsScore(Integer.parseInt(gcsScore));
        }
        if (!CommonUtils.checkNull(treatMeasure)) {
            dispatchCase.setTreatMeasure(treatMeasure);
        }
        if (!CommonUtils.checkNull(medicine)) {
            dispatchCase.setMedicine(medicine);
        }
        dispatchCase.setFormStatus(1);
        if (!CommonUtils.checkNull(hospitalID) && !"null".equals(hospitalID)) {
            final Hospital hospitalServiceById = hospitalService.getById(hospitalID);
            if (CommonUtils.checkNull(hospitalServiceById)) {
                throw new CustomException("目标医院有误");
            }
            dispatchCase.setHospital(hospitalServiceById.getHospitalName());
            dispatchCase.setHospitalID(hospitalID);
        }
        dispatchCase.setVin(dispatchServiceById.getVin());
        dispatchCase.setTime(LocalDateTime.now());
        dispatchCase.setUid(uid);
        dispatchCase.setFlow(dispatchServiceById.getFlow());
        final QueryWrapper<DispatchCase> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dispatchID", dispatchServiceById.getDispatchID());
        final boolean save = dispatchCaseService.update(dispatchCase, queryWrapper);
        return AjaxResult.AutoResponse(save);
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    @ApiOperation(value = "病历查询", notes = "病历查询", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pNum", value = "第几页", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "pSize", value = "每页多少", dataType = "int", defaultValue = "100"),
            @ApiImplicitParam(name = "date", value = "日期", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "minDate", value = "最小时间段", paramType = "form", dataType = "String", defaultValue = "00:00:00"),
            @ApiImplicitParam(name = "maxDate", value = "最大时间段", paramType = "form", dataType = "String", defaultValue = "23:59;59"),
            @ApiImplicitParam(name = "vin", value = "车牌号", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "hospital", value = "医院", paramType = "form", dataType = "String"),
    })
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数不正确"),
            @ApiResponse(code = 404, message = "404请求路径不正确"),
            @ApiResponse(code = 200, response = DispatchCase.class, message = "响应")
    })
    public Object list(@RequestParam(value = "pNum", defaultValue = "1") Integer pNum,
                       @RequestParam(value = "pSize", defaultValue = "100") Integer pSize,
                       @RequestParam(value = "date", defaultValue = "null") String date,
                       @RequestParam(value = "minDate", defaultValue = "00:00:00") String minDate,
                       @RequestParam(value = "maxDate", defaultValue = "23:59:59") String maxDate,
                       @RequestParam(value = "vin", required = false) String vin,
                       @RequestParam(value = "hospital", required = false) String hospital
    ) {
        PadUserLoginResult padLoginUser = padCommonUtil.getPadLoginUser();
        Page<DispatchCase> page = new Page<>(pNum, pSize);
        final QueryWrapper<DispatchCase> queryWrapper = new QueryWrapper<>();
        String[] caseParam = {"dispatch_caseID", "flow", "patient_name", "patient_sex", "patient_age", "major_case", "base_help", "time"};
        queryWrapper.select(caseParam);
        queryWrapper.eq("uid", padLoginUser.getUid().longValue())
                .eq("form_status", 1).
                like(!CommonUtils.checkNull(hospital), "hospital", hospital).
                eq(!CommonUtils.checkNull(vin), "vin", vin).
                between(!date.equals("null"), "time", date + ' ' + minDate, date + ' ' + maxDate);
        final IPage<DispatchCase> iPage = dispatchCaseService.page(page, queryWrapper);
        return AjaxResult.success(ResultMapUtil.customerObjFieldPage(iPage, caseParam));
    }

    @RequestMapping(value = "/getOne")
    @ApiOperation(value = "获取病历详情", notes = "获取病历详情", produces = "application/json")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "调度Id", dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数不正确"),
            @ApiResponse(code = 404, message = "404请求路径不正确"),
            @ApiResponse(code = 200, response = DispatchCase.class, message = "响应")
    })
    public Object get(@RequestParam(value = "id") Integer id) {
        final HashMap<String, Object> map = Maps.newHashMap();
        final QueryWrapper<DispatchCase> queryWrapper1 = new QueryWrapper<>();
        String[] param1 = {"dispatch_caseID", "patient_name", "patient_sex", "patient_age", "patient_mobile", "patient_address", "major_case", "base_help",
                "treatment_record", "medicine_sensitive", "nhiss_score", "gcs_score", "treat_measure", "medicine", "hospital", "patient_id","ecg_image","br_image"};
        queryWrapper1.eq("dispatchID", id).select(param1);
        final DispatchCase byId = dispatchCaseService.getOne(queryWrapper1);
        if (CommonUtils.checkNull(byId)) {
            throw new CustomException("无效的参数");
        }
        map.put("dispatchCase", ResultMapUtil.customerObjField(byId, param1));
        final QueryWrapper<Patient> queryWrapper = new QueryWrapper<>();
        String[] param = {"name", "phone", "sex", "age", "patient_local", "patient_card"};
        queryWrapper.select(param).eq("patientId", byId.getPatientId());
        final Patient patientServiceById = patientService.getOne(queryWrapper);
        map.put("patient120", ResultMapUtil.customerObjField(patientServiceById, param));
        return AjaxResult.success(map);
    }

    @RequestMapping(value = "/getinfo")
    @ApiOperation(value = "历史病历-获取病历详情", notes = "获取病历详情", produces = "application/json")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "病历Id", dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数不正确"),
            @ApiResponse(code = 404, message = "404请求路径不正确"),
            @ApiResponse(code = 200, response = DispatchCase.class, message = "响应")
    })
    public Object getInfo(@RequestParam(value = "id") Integer id) {
        final HashMap<String, Object> map = Maps.newHashMap();
        final QueryWrapper<DispatchCase> queryWrapper1 = new QueryWrapper<>();
        String[] param1 = {"dispatch_caseID", "patient_name", "patient_sex", "patient_age", "patient_mobile", "patient_address", "major_case", "base_help",
                "treatment_record", "medicine_sensitive", "nhiss_score", "gcs_score", "treat_measure", "medicine", "hospital"};
        queryWrapper1.eq("dispatch_caseID", id).select(param1);
        final DispatchCase byId = dispatchCaseService.getOne(queryWrapper1);
        map.put("dispatchCase", ResultMapUtil.customerObjField(byId, param1));
        final QueryWrapper<Patient> queryWrapper = new QueryWrapper<>();
        String[] param = {"name", "phone", "sex", "age", "patient_local", "patient_card"};
        queryWrapper.select(param).eq("patientId", byId.getPatientId());
        final Patient patientServiceById = patientService.getOne(queryWrapper);
        map.put("patient120", ResultMapUtil.customerObjField(patientServiceById, param));
        return AjaxResult.success(map);
    }

    @RequestMapping(value = "/update")
    @ResponseBody
    @ApiOperation(value = "更新病历", notes = "更新病历", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientName", value = "患者姓名", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "patientSex", value = "患者性别", paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "patientAge", value = "患者年龄", paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "patientMobile", value = "患者联系方式", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "majorCase", value = "主诉情况", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "baseHelp", value = "初步诊断", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "treatmentRecord", value = "既往病史", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "medicineSensitive", value = "过敏史", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "treatMeasure", value = "抢救措施", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "medicine", value = "用药情况", paramType = "form", dataType = "String"),
            @ApiImplicitParam(name = "hospitalID", value = "医院编号", paramType = "form", dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    @Transactional
    public Object update(
            @RequestParam(value = "patientName", required = false) String patientName,
            @RequestParam(value = "patientSex", required = false) Integer sex,
            @RequestParam(value = "patientAge", required = false) Integer patientAge,
            @RequestParam(value = "patientMobile", required = false) String patientMobile,
            @RequestParam(value = "patientAddress", required = false) String patientAddress,
            @RequestParam(value = "majorCase", required = false) String majorCase,
            @RequestParam(value = "baseHelp", required = false) String baseHelp,
            @RequestParam(value = "treatmentRecord", required = false) String treatmentRecord,
            @RequestParam(value = "medicineSensitive", required = false) String medicineSensitive,
            @RequestParam(value = "treatMeasure", required = false) String treatMeasure,
            @RequestParam(value = "medicine", required = false) String medicine,
            @RequestParam(value = "hospitalID", required = false) Integer hospitalID
    ) {
        final PadUserLoginResult padLoginUser = doctorAndNurseCommonUtil.getPadLoginUser();
        final Dispatch dispatch = doctorAndNurseCommonUtil.getDispatch();
        Integer dispatchCaseID = dispatch.getDispatchID();
        Integer changePersonID = padLoginUser.getUserMark();
        Integer changePersonType;
        if (padLoginUser.getRole().equals("DOCTOR")) {
            changePersonType = 1;
        } else {
            changePersonType = 2;
        }
        //初始化分隔符
        String splitChar = " ,";
        StringBuilder content = new StringBuilder();
        final DispatchCase dispatchCase = new DispatchCase();

        //先查询之间的数据 与现有数据进行数据比对 得出哪些数据进行了修改


        final DispatchCase caseOne = dispatchCaseService.getById(dispatchCaseID);
        if (CommonUtils.checkNull(caseOne)) throw new CustomException("查询结果为空,请检查入参");
        dispatchCase.setDispatchCaseid(dispatchCaseID);
        //判断患者姓名
        if (!CommonUtils.checkNull(patientName) && !caseOne.getPatientName().equals(patientName)) {
            dispatchCase.setPatientName(patientName);
            content.append("将患者姓名:").append(caseOne.getPatientName()).append("改为:").append(patientName).append(splitChar);
        }
        //判断患者性别
        if (!CommonUtils.checkNull(sex) && caseOne.getPatientSex() != sex) {
            dispatchCase.setPatientSex(sex);
            String oldSex = getChsex(caseOne.getPatientSex());
            String newSex = getChsex(sex);
            content.append("患者性别:").append(oldSex).append("改为:").append(newSex).append(splitChar);
        }
        //判断患者年龄
        if (!CommonUtils.checkNull(patientAge) && !caseOne.getPatientAge().equals(patientAge)) {
            dispatchCase.setPatientAge(patientAge);
            content.append("患者年龄:").append(caseOne.getPatientAge()).append("改为:").append(patientAge).append(splitChar);
        }
        //判断患者联系方式
        if (!CommonUtils.checkNull(patientMobile) && !caseOne.getPatientMobile().equals(patientMobile)) {
            dispatchCase.setPatientMobile(patientMobile);
            content.append("联系方式:").append(caseOne.getPatientMobile()).append("改为:").append(patientMobile).append(splitChar);
        }
        //判断患者家庭住址
        if (!CommonUtils.checkNull(patientAddress) && !caseOne.getPatientAddress().equals(patientAddress)) {
            dispatchCase.setPatientAddress(patientAddress);
            content.append("家庭住址:").append(caseOne.getPatientAddress()).append("改为:").append(patientAddress).append(splitChar);
        }
        //判断患者主要症状
        if (!CommonUtils.checkNull(majorCase) && !caseOne.getMajorCase().equals(majorCase)) {
            dispatchCase.setMajorCase(majorCase);
            content.append("主要症状:").append(caseOne.getMajorCase()).append("改为:").append(majorCase).append(splitChar);
        }
        //判断初步诊断
        if (!CommonUtils.checkNull(baseHelp) && !caseOne.getBaseHelp().equals(baseHelp)) {
            dispatchCase.setBaseHelp(baseHelp);
            content.append("初步诊断:").append(caseOne.getBaseHelp()).append("改为:").append(baseHelp).append(splitChar);
        }
        //判断既往病史
        if (!CommonUtils.checkNull(treatmentRecord) && !caseOne.getTreatmentRecord().equals(treatmentRecord)) {
            dispatchCase.setTreatmentRecord(treatmentRecord);
            content.append("既往病史:").append(caseOne.getTreatmentRecord()).append("改为:").append(treatmentRecord).append(splitChar);
        }
        //判断过敏史
        if (!CommonUtils.checkNull(medicineSensitive) && !caseOne.getMedicineSensitive().equals(medicineSensitive)) {
            dispatchCase.setMedicineSensitive(medicineSensitive);
            content.append("过敏史:").append(caseOne.getMedicineSensitive()).append("改为:").append(medicineSensitive).append(splitChar);
        }
        //判断抢救措施
        if (!CommonUtils.checkNull(treatMeasure) && !caseOne.getTreatMeasure().equals(treatMeasure)) {
            dispatchCase.setTreatMeasure(treatMeasure);
            content.append("抢救措施:").append(caseOne.getTreatMeasure()).append("改为:").append(treatMeasure).append(splitChar);
        }
        //判断用药情况
        if (!CommonUtils.checkNull(medicine) && !caseOne.getMedicine().equals(medicine)) {
            dispatchCase.setMedicine(medicine);
            content.append("用药情况:").append(caseOne.getMedicine()).append("改为:").append(medicine).append(splitChar);
        }
        //判断医院
        if (!CommonUtils.checkNull(hospitalID) && !caseOne.getHospitalID().equals(hospitalID)) {
            final Hospital hospitalServiceById = hospitalService.getById(hospitalID);
            dispatchCase.setHospitalID(hospitalID);
            dispatchCase.setHospital(hospitalServiceById.getHospitalName());
            content.append("送达医院:").append(caseOne.getHospital()).append("改为:").append(hospitalServiceById.getHospitalName()).append(splitChar);
        }
        //处理结束 开始操作数据
        Boolean dispatchCaseUpdate = false;
        if (!CommonUtils.checkNull(content.toString())) {
            final CaseChangeLog caseChangeLog = new CaseChangeLog();
            caseChangeLog.setChangeContent(content.toString());
            caseChangeLog.setCaseID(dispatchCaseID);
            caseChangeLog.setChangePersonID(changePersonID);
            caseChangeLog.setChangePersonType(changePersonType);
            caseChangeLog.setChangeTime(LocalDateTime.now());
            if (changePersonType == 1) {
                final Doctor doctor = doctorService.getById(changePersonID);
                caseChangeLog.setChangePerson(doctor.getName());
            } else {
                final Nurse nurse = nurseService.getById(changePersonID);
                caseChangeLog.setChangePerson(nurse.getName());
            }
            caseChangeLogService.save(caseChangeLog);
            dispatchCaseUpdate = dispatchCaseService.updateById(dispatchCase);
        }
        if (dispatchCaseUpdate) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error("无数据更新");
        }
    }

    @RequestMapping(value = "/patient/120/info")
    @ResponseBody
    @ApiOperation(value = "电子病历-普通病历-第一行", notes = "电子病历-普通病历-第一行", produces = "application/json")
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    /**
     * 获取调度中的初始病历
     */
    public Object getDispatchCaseIng() {
        final Dispatch UserLoginInfo = doctorAndNurseCommonUtil.getDispatch();
        final QueryWrapper<Patient> QueryWrapper = new QueryWrapper<>();
        QueryWrapper.eq("patientId", UserLoginInfo.getPatientID());
        final Patient patientServiceInfo = patientService.getOne(QueryWrapper);
        return AjaxResult.success(patientServiceInfo);
    }

    @RequestMapping(value = "/patient/case/info")
    @ResponseBody
    @ApiOperation(value = "电子病历-普通病历-患者信息", notes = "电子病历-普通病历-患者信息", produces = "application/json")
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    /**
     * 获取调度中的病历的初始信息
     */
    public AjaxResult getDispathcCaseNewinfo() {
        final Dispatch dispatchInfo = doctorAndNurseCommonUtil.getDispatch();
        final QueryWrapper<DispatchCase> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dispatchID", dispatchInfo.getDispatchID());
        final DispatchCase one = dispatchCaseService.getOne(queryWrapper);
        String[] param = {"patient_name", "patient_sex", "patient_age", "patient_mobile", "patient_address", "hospital", "major_case", "base_help",
                "treatment_record", "medicine_sensitive", "nhiss_score", "gcs_score", "treat_measure", "medicine", "form_status", "hospitalID", "form_status"};
        final Map<String, Object> stringObjectMap = ResultMapUtil.customerObjField(one, param);
        return AjaxResult.success(stringObjectMap);
    }

    @RequestMapping(value = "/allCarVin")
    @ResponseBody
    @ApiOperation(value = "车辆车牌列表", notes = "车辆车牌列表", produces = "application/json")
    @ApiResponses({
            @ApiResponse(code = 200, response = AjaxResultData.class, message = "响应")
    })
    public AjaxResult getAllCarVin() {
        PadUserLoginResult padLoginUser = padCommonUtil.getPadLoginUser();
        final List<Car> carList = carService.list(new QueryWrapper<Car>().eq("uid", padLoginUser.getUid()));
        String[] param = {"carID", "vin"};
        return AjaxResult.success(ResultMapUtil.customerObjFields(carList, param));
    }

    /**
     * 根据性别int类型 转换为String 方便查看
     *
     * @param sex
     * @return
     */
    private String getChsex(Integer sex) {
        String chSex = "";
        switch (sex) {
            case 0:
                chSex = "未知";
                break;
            case 1:
                chSex = "男";
                break;
            case 2:
                chSex = "女";
                break;
            default:
                chSex = "未知";
        }
        return chSex;
    }
}
